package com.woniuxy.propertyjava.controller;

import com.woniuxy.propertyjava.entity.OldPeople;
import com.woniuxy.propertyjava.entity.PageBean;
import com.woniuxy.propertyjava.entity.Registered;
import com.woniuxy.propertyjava.entity.ResponseResult;
import com.woniuxy.propertyjava.service.OldPeopleService;
import com.woniuxy.propertyjava.service.RegisteredService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class OldPeopleController {

    @Autowired
    private OldPeopleService oldPeopleService;

    //路径变量参数
    //条件查询+分页
    @PostMapping("/oldpeople/{pageIndex}/{pageSize}")
    public ResponseResult<PageBean<OldPeople>>
        getAllOldPeople(@PathVariable("pageIndex") int pageIndex,
                             @PathVariable("pageSize") int pageSize,
                             @RequestBody OldPeople oldPeople){
        System.out.println("查询条件："+oldPeople);
        System.out.println("pageIndex："+pageIndex);
        System.out.println("pageSize："+pageSize);
        PageBean<OldPeople> pageBean= oldPeopleService.getAllOldPeople(oldPeople,pageIndex,pageSize);
        ResponseResult<PageBean<OldPeople>> responseResult=
                new ResponseResult<>(200,"ok",pageBean);
        return responseResult;
    }

    //添加人员
    @PostMapping("/oldpeople")
    public ResponseResult addOldPeople(@RequestBody OldPeople oldPeople){
        System.out.println("添加人员"+oldPeople);
        oldPeopleService.getinsert(oldPeople);
        return new ResponseResult<>(200, "添加成功", null);
    }

    //修改人员
    @PutMapping("/oldpeople")
    public ResponseResult modifyOldPeople(@RequestBody OldPeople oldPeople){
        System.out.println("修改人员"+oldPeople);
        oldPeopleService.getupdate(oldPeople);
        return new ResponseResult<>(200, "修改成功", null);
    }

    //删除人员
    @DeleteMapping("/oldpeople/{opid}")
    public ResponseResult removeOldPeople(@PathVariable("opid") int opid){
        System.out.println("删除人员"+opid);
        oldPeopleService.getdeleteById(opid);
        return new ResponseResult<>(200, "删除成功", null);
    }






}
